﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;

namespace RA.TextServices
{
    //public class GrabberAgent
    //{
    //    public Dictionary<string, int> GetResults()
    //    {
    //        return DataOperate(); 
    //    }

    //    Dictionary<string, int> DataOperate()
    //    {
    //        var UrlTemplate = @"http://mirknig.com/knigi/military_history/page/%1-24%/";
    //        var BodyTemplate = "/html";
    //        var Keys = new List<string>() { "Фотоальбом" };

    //        var match = Regex.Match(UrlTemplate, @"%(?<From>[0-9]+)-(?<To>[0-9]+)%");

    //        var val = match.Value;
    //        var from = match.Groups["From"].Value;
    //        var to = match.Groups["To"].Value;

    //        int fromInt = Int32.Parse(from);
    //        int toInt = Int32.Parse(to);


    //        var keyDict = new Dictionary<string, int>();
    //        for(var i =fromInt; i < toInt; ++i)
    //        {
    //            var nextUrl = UrlTemplate.Replace(val, i.ToString());
    //            var content = HtmlUtilities.GetHtmlContent(nextUrl);
    //            var doc = HtmlUtilities.FromHtml(new StringReader(content));

    //            foreach (var key in Keys)
    //            {
    //                int count = 0;
                    
    //                foreach (XmlNode element in doc.SelectNodes(BodyTemplate))
    //                {
    //                    var body = element.InnerText;
    //                    count += Regex.Matches(body, key).Count;
    //                }
    //                if (keyDict.ContainsKey(key))
    //                    keyDict[key] += count;
    //                else
    //                    keyDict.Add(key, count);
    //            }
    //        }

    //        return keyDict;
    //    }
    //}
}
